//============================================================================
// Copyright (C) 2008-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include "RcSktLib.h"
#include <VxUtilLib/VxParse.h>

//============================================================================
//=== constructor ===//
RcSktAccept::RcSktAccept()
{
	m_eSktType = eSktTypeTcpAccept;
}
//============================================================================
//=== destructor ===//
RcSktAccept::~RcSktAccept()
{
}


//============================================================================
//! called when socket is accepted
RCODE	RcSktAccept::DoAccept( RcSktAcceptMgr * poMgr )
{
	m_poSktMgr = poMgr;
	m_eSktCallbackReason = eSktCallbackReasonConnecting;
	// get the peer address
	m_rcLastError = DoGetRmtAddress();
	if( m_rcLastError )
	{
		m_eSktCallbackReason = eSktCallbackReasonConnectError;
		log_msg( 0, "RcSktAccept::DoAccept: get remote ip error %s\n", 
						DescribeSktError( m_rcLastError ) );
		m_pfnRecieve( this );
		return m_rcLastError;
	}

	// tell user we connecting
	m_pfnRecieve( this );
	// make a usefull thread name
	std::string strThreadName;
	StdStringFormat( strThreadName, "VxSktBaseAccept%d", m_iSktId );
	return StartRecieveThread( strThreadName.c_str() );

}

